import {createRouter, createWebHistory, RouteRecordRaw} from 'vue-router'
import Home from '../views/Home.vue'
import Input from '../views/user/input-index.vue'
import BookInput from '../views/user/bookview/book-input.vue'
import Success from '../views/success.vue'
import ProblemBooks from '../views/user/bookview/problems-book.vue'
import BookDetail from '../views/user/bookview/book-detail.vue'
import PaperInput from '../views/user/paperview/paper-input.vue'
import ProblemPapers from '../views/user/paperview/problems-paper.vue'
import PaperDetail from '../views/user/paperview/paper-detail.vue'


import store from "@/store";

const routes: Array<RouteRecordRaw> = [
    {
        path: '/',
        name: 'Home',
        component: Home
    }, {
        path: '/input',
        name: 'Input',
        component: Input
    }, {
        path: '/book-input',
        name: 'BookInput',
        component: BookInput
    }, {
        path: '/success',
        name: 'Success',
        component: Success
    }, {
        path: '/problemBooks',
        name: 'ProblemBooks',
        component: ProblemBooks
    }, {
        path: '/bookDetail',
        name: 'BookDetail',
        component: BookDetail
    }, {
        path: '/paper-input',
        name: 'PaperInput',
        component: PaperInput
    },{
        path: '/problemPaper',
        name: 'ProblemPaper',
        component:ProblemPapers
    },{
        path: '/paperDetail',
        name: 'PaperDetail',
        component: PaperDetail
    }
]


const router = createRouter({
    history: createWebHistory(process.env.BASE_URL),
    routes
})

router.beforeEach((to, from, next) => {
    if (to.path === '/') return next();

    const User = window.sessionStorage.getItem("USER");
    if (!User) return next('/');

    next();


})

export default router;
